package configs

import (
	jsoniter "github.com/json-iterator/go"
	"github.com/mojocn/base64Captcha"
	"os"
	"path/filepath"
	"strings"
)

var Json = jsoniter.ConfigCompatibleWithStandardLibrary // json解析器

var (
	AdminPassword = os.Getenv("pwd")    // 管理员密码
	JWTSecret     = os.Getenv("secret") // jwt密钥
)

// 目录
var (
	RootPath = func() string {
		path, err := os.Getwd()
		if err != nil {
			panic(err)
		}
		return path
	}()
	CrtPath   = filepath.Join(RootPath, "configs", "kkkunny.top_chain.crt") // 证书
	KeyPath   = filepath.Join(RootPath, "configs", "kkkunny.top_key.key")   // 密钥
	FrontPath = filepath.Join(RootPath, "web")                              // 前端目录
	TipsPath  = filepath.Join(RootPath, "configs", "tips.txt")              // 名人名言
)

// 验证码
var CaptchaStore = base64Captcha.DefaultMemStore

// 名人名言
var Tips []string

func init() {
	// 名人名言
	content, err := os.ReadFile(TipsPath)
	if err != nil {
		panic(err)
	}
	lines := strings.Split(string(content), "\n")
	for _, line := range lines {
		line = strings.TrimSpace(line)
		if len(line) > 0 {
			Tips = append(Tips, line)
		}
	}
}
